package com.pmsystem.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.pmsystem.pojo.Accident;
import com.pmsystem.pojo.CleanArea;
import com.pmsystem.pojo.CleanMan;
import com.pmsystem.pojo.CleanMis;
import com.pmsystem.pojo.News;
import com.pmsystem.service.CleanService;



@Controller
@RequestMapping("admin/clean")
public class CleanController {

	@Autowired
	CleanService cleanService;
	
	/**
	 * <p>Title: index</p >  
	 * <p>Description: 主页路径</p >  
	 * @author 魏家洛
	 * @param mv
	 * @return
	 */
	@RequestMapping("index")
	public String index(ModelAndView mv) {
		return "clean/clean_index";
	}
	
	
	//保洁区域操作
	/**
	 * <p>Title: findAreaPage</p >  
	 * <p>Description:传入页码和页大小获取页码对应保洁区域信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findareapage")
	@ResponseBody
	public Map findAreaPage(Integer pageNo,Integer pageSize,String condition){
		return cleanService.findAreaPage(pageNo,pageSize,condition);
	}
	/**
	 * <p>Title: findAllArea</p >  
	 * <p>Description:传入条件查询所有区域信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findallarea")
	@ResponseBody
	public Map<String,Object> findAllArea(String keyword){
		return cleanService.findAllArea(keyword);
	}
	/**
	 * <p>Title: deleteclean</p >
	 * <p>Description:删除保洁区域信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deletearea")
	@ResponseBody
	public Map<String,Object> deleteArea(Integer id){
		Map<String,Object> map = new HashMap<>();
		boolean flag = cleanService.deleteArea(id);
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	@RequestMapping("deleteallarea")
	@ResponseBody
	public Map<String,Object> deleteAllArea(int[] id){
		Map<String,Object> map = new HashMap<>();
		boolean flag=false;
		for (int i : id) {
			flag = cleanService.deleteArea(i);
		}
		
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	/**
	 * <p>Title: updateArea</p >  
	 * <p>Description: 通过id查找保洁区域信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	@RequestMapping("findareabyid")
	@ResponseBody
	public Map<String, Object> findAreabyid(Integer id){
		Map<String, Object> map = new HashMap<>();
		CleanArea cleanArea = cleanService.selectArea(id);
		map.put("cleanArea", cleanArea);
		return map;
	}
	@RequestMapping("updatearea")
	@ResponseBody
	public Map<String,Object> updateArea(CleanArea cleanArea){
		Map<String,Object> map = new HashMap<>();
		boolean flag = cleanService.updateArea(cleanArea);
		if(flag)
			map.put("msg", "success");
		else
			map.put("msg", "error");
		return map;
	}
	/**
	 * <p>Title: addArea</p >  
	 * <p>Description: 添加保洁区域信息</p >  
	 * @author 魏家洛
	 * @param cleanAreaName
	 * @return
	 */
	@RequestMapping("addarea")
	@ResponseBody
	public Map<String,Object> addArea(String areaName){
		Map<String,Object> map = new HashMap<>();
		boolean flag = cleanService.addArea(areaName);
		if(flag)
			map.put("msg", "success");
		else
			map.put("msg", "error");
		return map;
	}
	
	
	
	//保洁人员操作
	/**
	 * <p>Title: findManPage</p >  
	 * <p>Description:传入页码和页大小获取页码对应保洁人员信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findmanpage")
	@ResponseBody
	public Map findManPage(Integer pageNo,Integer pageSize,String condition){
		return cleanService.findManPage(pageNo,pageSize,condition);
	}
	/**
	 * <p>Title: findAllMan</p >  
	 * <p>Description:传入条件查询所有人员信息</p >  
	 * @author 魏家洛
	 * @param condition
	 * @return
	 */
	@RequestMapping("findallman")
	@ResponseBody
	public Map<String, Object> findAllMan(String keyword){
		return cleanService.findAllMan(keyword);
	}
	/**
	 * <p>Title: deleteMan</p >  
	 * <p>Description:删除保洁人员信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deleteman")
	@ResponseBody
	public Map<String, Object> deleteMan(Integer id){
		Map<String, Object> map = new HashMap<>();
		boolean flag = cleanService.deleteMan(id);
		if(flag)
			map.put("msg", "success");
		else
			map.put("msg", "error");
		return map;
	}
	@RequestMapping("deleteallman")
	@ResponseBody
	public Map<String,Object> deleteAllMan(int[] id){
		Map<String,Object> map = new HashMap<>();
		boolean flag=false;
		for (int i : id) {
			flag = cleanService.deleteMan(i);
		}
		
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	/**
	 * <p>Title: findManbyid</p >  
	 * <p>Description:通过id查找保洁人员信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	@RequestMapping("findmanbyid")
	@ResponseBody
	public Map<String, Object> findManbyid(Integer id){
		Map<String, Object> map = new HashMap<>();
		CleanMan cleanMan = cleanService.selectMan(id);
		map.put("cleanMan", cleanMan);
		return map;
	}
	/**
	 * <p>Title: updateMan</p >  
	 * <p>Description:更新保洁人员信息</p >  
	 * @author 魏家洛
	 * @param cleanMan
	 * @return
	 */
	@RequestMapping("updateman")
	@ResponseBody
	public Map<String,Object> updateMan(CleanMan CleanMan){
		Map<String,Object> map = new HashMap<>();
		boolean flag = cleanService.updateMan(CleanMan);
		if(flag)
			map.put("msg", "success");
		else
			map.put("msg", "error");
		return map;
	}
	/**
	 * <p>Title: addMan</p >  
	 * <p>Description: 添加保洁人员信息</p >  
	 * @author 魏家洛
	 * @param cleanMan
	 * @return
	 */
	@RequestMapping("addman")
	@ResponseBody
	public Map<String,Object> addMan(CleanMan cleanMan){
		Map<String,Object> map = new HashMap<>();
		boolean flag = cleanService.addMan(cleanMan);
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
		
		
		
	//保洁任务操作
	/**
	 * <p>Title: findMisPage</p >  
	 * <p>Description:传入页码和页大小获取页码对应保洁任务信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findmispage")
	@ResponseBody
	public Map findMisPage(Integer pageNo,Integer pageSize,String condition,String startTime,String endTime){
		return cleanService.findMisPage(pageNo,pageSize,condition,startTime,endTime);
	}
	/**
	 * <p>Title: findAllMis</p >  
	 * <p>Description::查找符合条件的所有保洁任务信息</p >  
	 * @author 魏家洛
	 * @return
	 */
	@RequestMapping("findallmis")
	@ResponseBody
	public Map<String, Object> findAllMis(String keyword,String startTime,String endTime){
		return cleanService.findAllMis(keyword,startTime,endTime);
	}
	/**
	 * <p>Title: deleteMis</p >  
	 * <p>Description:删除保洁任务信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deletemis")
	@ResponseBody
	public Map<String,Object> deleteMis(Integer id){
		Map<String,Object> map = new HashMap<>();
		boolean flag = cleanService.deleteMis(id);
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	@RequestMapping("deleteallmis")
	@ResponseBody
	public Map<String,Object> deleteAllMis(int[] id){
		Map<String,Object> map = new HashMap<>();
		boolean flag=false;
		for (int i : id) {
			flag = cleanService.deleteMis(i);
		}
		
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	/**
	 * <p>Title: findMisById</p >  
	 * <p>Description: 根据id查找保洁任务信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("findmisbyid")
	@ResponseBody
	public Map<String, Object> findMisById(Integer id){
		Map<String, Object> map = new HashMap<>();
		CleanMis cleanMis =cleanService.selectMis(id);
		map.put("cleanMis", cleanMis);
		return map;
	}
	/**
	 * <p>Title: updateMis</p >  
	 * <p>Description: 更新保洁任务信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	
	@RequestMapping("updatemis")
	@ResponseBody
	public Map<String,Object> updateMis(CleanMis cleanMis){
		Map<String,Object> map = new HashMap<>();
		boolean flag = cleanService.updateMis(cleanMis);
		if(flag)
			map.put("msg", "success");
		else
			map.put("msg", "error");
		return map;
	}
	/**
	 * <p>Title: addMis</p >  
	 * <p>Description: 添加保洁任务信息</p >  
	 * @author 魏家洛
	 * @param cleanMis
	 * @return
	 */
	@RequestMapping("addmis")
	@ResponseBody
	public Map<String,Object> addMis(CleanMis cleanMis){
		Map<String,Object> map = new HashMap<>();
		boolean flag = cleanService.addMis(cleanMis);
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	/**
	 * <p>Title: beFinish</p >  
	 * <p>Description:将任务标记为已完成</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("befinish")
	@ResponseBody
	public Map<String, Object> beFinish(Integer id){
		Map<String, Object> map = new HashMap<>();
		boolean flag = cleanService.beFinish(id);
		if(flag)
			map.put("msg", "success");
		else
			map.put("msg", "error");
		return map;
	}
	/**
	 * <p>Title: getProgress</p >  
	 * <p>Description:获取当天任务进度</p >  
	 * @author 魏家洛
	 * @return
	 */
	@RequestMapping("getprogress")
	@ResponseBody
	public int getProgress(String currentDate) {
		System.out.println(currentDate);
		return cleanService.getProgress(currentDate);
	}
}
